package service;

import com.alibaba.fastjson.JSON;
import mapper.CommonMapper;
import mapper.ConsoleMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pojos.common.ReplyMessage;
import pojos.subject.ClassInfoManager;
import pojos.subject.UserRelationshipManager;

import javax.annotation.Resource;
import java.util.List;

/**
 * 科目信息服务
 */
public class SubjectInfoService {

    private Logger logger = LoggerFactory.getLogger(SubjectInfoService.class);

    @Resource(name = "commonMapper")
    private CommonMapper commonMapper;

    @Resource(name = "consoleMapper")
    private ConsoleMapper consoleMapper;

    /**
     * 修改用户关系
     */
    public ReplyMessage updateRelationship(UserRelationshipManager manager){
        ReplyMessage replyMessage = new ReplyMessage();

        try {
            commonMapper.updateUserRelationship(manager);
            replyMessage.setStatus(200);
            return replyMessage;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("修改用户关系异常，关系ID："+manager.getRelationId());

            replyMessage.setStatus(500);
            replyMessage.setInfo("服务器异常，请稍后重试！");
            return replyMessage;
        }
    }

    /**
     * 管理员查询用户当天课程信息
     */
    public ReplyMessage queryUserCurrentClassInfo(){
        ReplyMessage replyMessage = new ReplyMessage();
        try {
            List<ClassInfoManager> classInfoManagerList = consoleMapper.queryUserCurrentClassInfo();
            if(classInfoManagerList != null){
                replyMessage.setStatus(200);
                replyMessage.setInfo(JSON.toJSONString(classInfoManagerList));
                return replyMessage;
            }
            replyMessage.setStatus(400);
            replyMessage.setInfo("查询结果为空！");
            return replyMessage;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("管理员查询用户当天课程信息异常！");

            replyMessage.setStatus(500);
            replyMessage.setInfo("服务器异常，请稍后重试！");
            return replyMessage;
        }
    }
}
